package com.hzpd.hainan.module.usercenter.adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hzpd.hainan.R;
import com.hzpd.hainan.app.ListBaseAdapter;
import com.hzpd.hainan.model.usercenter.CollectBean;
import com.hzpd.hainan.utils.SPUtil;


public class CollectionAdapter extends ListBaseAdapter<CollectBean> {
	private SPUtil spu;

	public CollectionAdapter(Activity activity){
		super(activity);
		spu= SPUtil.getInstance();
	}

	public void deleteItem(int position){
		this.list.remove(position);
		notifyDataSetChanged();
	}


	@Override
	public View getMyView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder=null;

		if(convertView==null){
			holder=new ViewHolder();
			convertView=inflater.inflate(R.layout.item_collection, parent,false);
			holder.iv_item=(ImageView)convertView.findViewById(R.id.iv_item_collect);
			holder.tv_content_item=(TextView) convertView.findViewById(R.id.tv_content_item_collect);
			holder.tv_sj_item=(TextView) convertView.findViewById(R.id.tv_time_item_collect);
			holder.type_item=(ImageView) convertView.findViewById(R.id.type_item_collect);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
		CollectBean cb=list.get(position);
		if (cb.getData().getImgs() != null && cb.getData().getImgs().size() > 0){
			Glide.with(context).load(cb.getData().getImgs().get(0)).crossFade().into(holder.iv_item);
		}

		holder.tv_content_item.setText(cb.getData().getTitle());
		holder.tv_sj_item.setText(cb.getData().getUpdateTime());
//
//		String sj=CalendarUtil.friendlyTime(cb.getDatetime());
//		if(!TextUtils.isEmpty(sj)){
////			holder.lehuo_sj_txt.setVisibility(View.VISIBLE);//暂时先不显示
//			holder.lehuo_sj_txt.setText(sj);
//		}
//
//		if("2".equals(cb.getType())){
//			LogUtils.i("img");
//			holder.type_item.setVisibility(View.VISIBLE);
//			holder.type_item.setImageResource(R.drawable.zq_subscript_album);
//		}else if("3".equals(cb.getType())){
//			LogUtils.i("img");
//			holder.lehuo_type.setVisibility(View.VISIBLE);
//			holder.lehuo_type.setImageResource(R.drawable.zq_subscript_video);
//		}else if("4".equals(cb.getType())){
//			LogUtils.i("img");
//			holder.lehuo_type.setVisibility(View.VISIBLE);
//			holder.lehuo_type.setImageResource(R.drawable.zq_subscript_html);
//		}else{
//			holder.lehuo_type.setVisibility(View.GONE);
//		}
		return convertView;
	}

	private static class ViewHolder{
		ImageView iv_item;
		TextView tv_content_item;
		TextView tv_sj_item;
		ImageView type_item;
	}
	
}
